import _ from "lodash"

export const debounce = (func, wait = 200, immediate = true) => {
	let timeout = null
	let isCreated = false

	return function () {
		let context = this
		let args = arguments
		if (!isCreated && immediate) {
			func.apply(this, arguments)
			isCreated = true
		} else if (!timeout) {
			timeout = setTimeout(function () {
				func.apply(context, args)
				clearTimeout(timeout)
				timeout = null
			}, wait)
		}
	}
}

